package com.finger.crowd.service.api.impl;

import com.finger.crowd.entity.Auth;
import com.finger.crowd.entity.AuthExample;
import com.finger.crowd.mapper.AuthMapper;
import com.finger.crowd.service.api.AuthService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class AuthServiceImpl implements AuthService {
    @Autowired
    private AuthMapper authMapper;

    @Override
    public List<Auth> getAllAuth() {
        return authMapper.selectByExample(new AuthExample());
    }

    @Override
    public List<Integer> getAllAuthByRoleId(Integer roleId) {
        List<Integer> roleIds = authMapper.selectByRoleId(roleId);
        return roleIds;
    }

    @Override
    public void deleteAuthByRoleId(Integer roleId) {
        authMapper.deleteAuthByRoleId(roleId);
    }

    @Override
    public int insertAuth(Map<String, List<Integer>> map) {
        List<Integer> authIdList = map.get("authIdList");
        List<Integer> list = map.get("roleId");
        Integer roleId = list.get(0);
        if (authIdList != null && authIdList.size() == 0) {
            authMapper.deleteAuthByRoleId(roleId);
            return 1;
        }
        return authMapper.insertAuth(roleId, authIdList);
    }

    @Override
    public List<String> getAuthNameByAdminId(Integer adminId) {
        return authMapper.selectAuthNameByAdminId(adminId);
    }


}
